#include <iostream>
#include <vector>
#include <numeric>
#include <map>

using namespace std;
using ll = long long;

void go() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<int> c(n + 1, 0);
	for (int x : a) c[x]++;
	vector<int> pc(n + 1);
	vector<int> nc(n + 1);
	while (k--) {
		int w = 0;
		while (c[w]) w++;
		nc.assign(n + 1, 0);
		for (int i = 0; i <= n; i++) {
			if (i < w && c[i] == 1) nc[i] += c[i];
			else nc[w] += c[i];
		}
		if (pc == nc) break;
		pc = c;
		c = nc;
	}
	
	auto res = c;
	if (k % 2 == 0) res = nc;
	else res = c;
	ll ans = 0;
	for (int i = 0; i <= n; i++) ans += ll(i) * res[i];
	cout << ans << endl;
	
	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t;
	cin >> t;
	while (t-- > 0) {
		go();
	}
	return 0;
}
